﻿Imports YvanSoftware.Orb
Public Class Form1
    Public SessionID As String = ""

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Or TextBox2.Text = "" Then
            MsgBox("All fields are required.")
        End If
        Dim oAuth As New Authentication(TextBox3.Text)
        If oAuth.performLogin(TextBox1.Text, TextBox2.Text) Then
            SessionID = oAuth.sessionID
            grpChannel.Visible = True
            fillCmbChannels()
            MsgBox("Succesfuly logged in.")
        Else
            grpChannel.Visible = False
            MsgBox("Login failed. Please check your API key, username and password.")
        End If
    End Sub

    Sub FillCmbChannels()
        Dim oChannels As New Streaming(TextBox3.Text, SessionID)
        ComboBox1.Items.Clear()
        oChannels.RetrieveChannels()
        Dim intTeller As Integer
        For intTeller = 1 To oChannels.lastChannel
            ComboBox1.Items.Add(oChannels.GetChannel(intTeller).Text)
        Next
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim oStream As New Streaming(TextBox3.Text, SessionID)

        Dim strChannel As String = ComboBox1.Text
        strChannel = "TD" & strChannel
        Debug.Print("channel:" & strChannel)
        Dim url As String = oStream.GetStreamingUri(Streaming.TYPE_ASX, strChannel, 320, 240)
        Debug.Print(url)
        Try
            Debug.Print(url)
            AxWindowsMediaPlayer1.URL = url
            AxWindowsMediaPlayer1.Ctlcontrols.play()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub AxWindowsMediaPlayer1_StatusChange(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxWindowsMediaPlayer1.StatusChange
        lblStatus.Text = AxWindowsMediaPlayer1.status
    End Sub
End Class
